﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using ComLib.ConfigService;
using ComLib.ComFun;

namespace ProcessConfig.ConfigType
{
    [Serializable]
    public class PhotoSize : SerializeBase
    {
        public PhotoSize()
            : base()
        {

        }

        /// <summary>
        /// 质检大小
        /// </summary>
        public Size CheckSize = new Size(427, 512);
       
        /// <summary>
        /// 摄像头照片大小
        /// </summary>
        public Size CameraSize = new Size(2048, 1536);      

        /// <summary>
        /// 预览控件大小
        /// </summary>
        public Size PictureBoxSize = new Size(600, 720);

        /// <summary>
        /// 预览图像大小
        /// </summary>
        public Size DisplayImageSize = new Size(1280, 1536);
      
        /// <summary>
        /// 出入境照片大小
        /// </summary>
        public static Size CRJPhotoSize = new Size(354, 472); 

        /// <summary>
        /// 身份证照片大小
        /// </summary>
        public static Size SFZPhotoSize = new Size(358, 441);

        
        protected PhotoSize(SerializationInfo si, StreamingContext context) :
            base(si, context)
        {
            CheckSize = (Size)si.GetValue("check", typeof(Size));
            CameraSize = (Size)si.GetValue("cam", typeof(Size));
            DisplayImageSize = (Size)si.GetValue("display", typeof(Size));     
            PictureBoxSize = (Size)si.GetValue("box", typeof(Size));        
        }

        public override void GetObjectData(SerializationInfo si, StreamingContext context)
        {
            base.GetObjectData(si, context);
            si.AddValue("check", CheckSize);
            si.AddValue("cam", CameraSize);
            si.AddValue("display", DisplayImageSize);
            si.AddValue("box", PictureBoxSize);
        }

        public override bool Serialize()
        {
            return Serializer.SaveToDatFile(ConfigFilePath, this);
        }

        public override bool Load()
        {
            return LoadFrom(ConfigFilePath);
        }

        public override bool LoadFrom(string path)
        {
            PhotoSize obj = (PhotoSize)Serializer.LoadFromDatFile(path);
            if (obj != null)
            {
                this._nowVer = obj._nowVer;
                this.CameraSize = obj.CameraSize;
                this.CheckSize = obj.CheckSize;
                this.DisplayImageSize = obj.DisplayImageSize;
                this.PictureBoxSize = obj.PictureBoxSize;
                return true;
            }
            else
            {
                ErrorMessage = Serializer.Message;
                return false;
            }
        }


        public bool IsEmpty()
        {
            return CheckSize.IsEmpty
                || CameraSize.IsEmpty
                || PictureBoxSize.IsEmpty
                || DisplayImageSize.IsEmpty;
        }
    }
}
